package com.yljk.mydoctor.utils;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.yilijk.base.utils.ClickUtils;
import com.yilijk.base.utils.CommonUtils;
import com.yljk.mydoctor.R;

public class PopWindowUtils {

    private static PopWindowUtils popWindowUtils;

    private Context context;

    public static synchronized PopWindowUtils getInstance() {
        if (popWindowUtils == null) {
            popWindowUtils = new PopWindowUtils();
        }
        return popWindowUtils;
    }


    public void init(Context context) {
        this.context = context;

        initPopTumour1(context);

    }


    private PopupWindow popTumour1;
    private View popTumour1View;

    /**
     * 初始化肿瘤未开通权限须知
     * @param context
     */
    void initPopTumour1(Context context) {
        if (context instanceof Activity){
            Activity activity = (Activity) this.context;
            popTumour1 = new PopupWindow();
            popTumour1View = activity.getLayoutInflater().inflate(R.layout.pop_tumour1, null);
            Button tomour1PopSure = (Button) popTumour1View.findViewById(R.id.tomour1_pop_sure);

            popTumour1.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
            popTumour1.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
            popTumour1.setContentView(popTumour1View);
            popTumour1.setFocusable(false);
            popTumour1.setOutsideTouchable(false);
            ClickUtils.setFastOnClickListener(tomour1PopSure, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (popTumour1!=null && popTumour1.isShowing()){
                        popTumour1.dismiss();
                        CommonUtils.setBackgroundAlpha(activity,1.0f);
                    }
                }
            });

            ClickUtils.setFastOnClickListener(popTumour1View.findViewById(R.id.tomour1_pop_close), new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (popTumour1!=null && popTumour1.isShowing()){
                        popTumour1.dismiss();
                        CommonUtils.setBackgroundAlpha(activity,1.0f);
                    }
                }
            });
        }
    }

    /**
     * 显示肿瘤未开通权限须知
     */
    public void showPopTumour1(){
        if (this.context instanceof Activity){
            Activity activity = (Activity) this.context;
            popTumour1.showAtLocation(activity.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
            CommonUtils.setBackgroundAlpha(activity,0.3f);
        }
    }

}
